package com.blakebeats;

import java.io.IOException;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

public class PlayDrums extends Activity {

	// initial setup of MediPlayer vars. give unique name to MediaPlayer vars by
	// adding 'MP' for clarity.
	MediaPlayer kickMP;
	MediaPlayer snareMP;
	MediaPlayer hiHatMP;
	MediaPlayer floorTomMP;
	MediaPlayer tomLeftMP;
	MediaPlayer tomRightMP;
	MediaPlayer rideMP;
	MediaPlayer crashMP;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.playdrums);

		// set up the drum sound
		final MediaPlayer kickMP = MediaPlayer.create(this, R.raw.kick);
		final MediaPlayer snareMP = MediaPlayer.create(this, R.raw.snare);
		final MediaPlayer hiHatMP = MediaPlayer.create(this, R.raw.hihat);
		final MediaPlayer floorTomMP = MediaPlayer.create(this, R.raw.floortom);
		final MediaPlayer tomLeftMP = MediaPlayer.create(this, R.raw.lefttom);
		final MediaPlayer tomRightMP = MediaPlayer.create(this, R.raw.righttom);
		final MediaPlayer rideMP = MediaPlayer.create(this, R.raw.ride);
		final MediaPlayer crashMP = MediaPlayer.create(this, R.raw.crash);

		// view that listens for touch events
		// final View touchView = findViewById(R.id.touchView);
		// view that displays x & y position
		// final TextView textView = (TextView) findViewById(R.id.textView);

		// function that displays x & y position
		// touchView.setOnTouchListener(new View.OnTouchListener() {
		// @Override
		// public boolean onTouch(View v, MotionEvent event) {
		// textView.setText("Drum Hit Position : "
		// + String.valueOf(event.getX()) + " x "
		// + String.valueOf(event.getY()));
		// return true;
		// }
		// });

		// setup buttons
		ImageView kickDrum = (ImageView) findViewById(R.id.kick);
		kickDrum.setAlpha(0);
		ImageView snareDrum = (ImageView) findViewById(R.id.snare);
		snareDrum.setAlpha(0);
		ImageView hiHat = (ImageView) findViewById(R.id.hihat);
		hiHat.setAlpha(0);
		ImageView floorTom = (ImageView) findViewById(R.id.floortom);
		floorTom.setAlpha(0);
		ImageView tomLeft = (ImageView) findViewById(R.id.tomleft);
		tomLeft.setAlpha(0);
		ImageView tomRight = (ImageView) findViewById(R.id.tomright);
		tomRight.setAlpha(0);
		ImageView ride = (ImageView) findViewById(R.id.ride);
		ride.setAlpha(0);
		ImageView crash = (ImageView) findViewById(R.id.crash);
		crash.setAlpha(0);

		// setup button listeners
		kickDrum.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				kickMP.start();
			}
		});

		snareDrum.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (snareMP.isPlaying()) {
					snareMP.stop();
				}
				snareMP.reset();
				try {
					snareMP.prepare();
				} catch (IllegalStateException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				snareMP.start();
			}
		});

		hiHat.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				hiHatMP.start();
			}
		});

		floorTom.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				floorTomMP.start();
			}
		});

		tomLeft.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				tomLeftMP.start();
			}
		});

		tomRight.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				tomRightMP.start();
			}
		});

		ride.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				rideMP.start();
			}
		});

		crash.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				crashMP.start();
			}
		});

	}

}